#include <linux/init.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include "stm32mp157_rcc.h"
#include "stm32mp157_gpio.h"

#define RCC_START       RCC
#define RCC_END         (RCC + sizeof(rcc_t) - 1)
#define GPIOZ_START     GPIOZ
#define GPIOZ_END       (GPIOZ + sizeof(gpio_t) - 1)
#define GPIOE_START     GPIOE
#define GPIOE_END       (GPIOE + sizeof(gpio_t) - 1)
#define GPIOF_START     GPIOF
#define GPIOF_END       (GPIOF + sizeof(gpio_t) - 1)

struct resource	led_res[] = {
	[0] = {
		.start = RCC_START,
		.end = RCC_END,
		.name = "rcc",
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = GPIOZ_START,
		.end = GPIOZ_END,
		.name = "gpioz",
		.flags = IORESOURCE_MEM,
	},
	[2] = {
		.start = GPIOE_START,
		.end = GPIOE_END,
		.name = "gpioe",
		.flags = IORESOURCE_MEM,
	},
	//========= 测试=============
	[3] = {
		.start = 11,
		.end = 11,
		.name = "test_irq",
		.flags = IORESOURCE_IRQ,
	},
	//==========================
	[4] = {
		.start = GPIOF_START,
		.end = GPIOF_END,
		.name = "gpiof",
		.flags = IORESOURCE_MEM,
	},
};

void led_dev_release(struct device *dev)
{
}

struct platform_device led_dev = {
	.name = "stm32mp157_led", //名称
	.id = 0, //ID用来区分每个设备
	.dev = {
		.release = led_dev_release,
	},
	.num_resources = ARRAY_SIZE(led_res),//资源个数
	.resource = led_res,//资源的起始地址
};

static int __init led_dev_init(void)
{
	return platform_device_register(&led_dev);
}

static void __exit led_dev_exit(void)
{
	platform_device_unregister(&led_dev);
}

module_init(led_dev_init);
module_exit(led_dev_exit);
MODULE_LICENSE("GPL");

